package com.hao.demo.springcloud.client.controller;

import com.hao.demo.springcloud.client.provider.DemoProvider;
import com.hao.demo.springcloud.client.provider.dto.DemoDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@Api("API测试")
@RequestMapping("/demo")
@RestController
public class DemoController {

    @Resource
    private DemoProvider demoProvider;

    @ApiOperation(value = "查询名称")
    @GetMapping("/queryName")
    public String queryName(@RequestParam("name") @ApiParam(value = "名称", required = true) @NotNull(message = "名称不能为空") String name){
        String obj = demoProvider.queryByName(name);
        return obj;
    }

    @ApiOperation(value = "创建DemoDTO")
    @PostMapping("/createDemo")
    public String createDemo(@RequestBody DemoDTO demoDTO){
        String str = demoProvider.createDemo(demoDTO);
        return str;
    }

    @ApiOperation(value = "查询DemoDTO")
    @GetMapping("/queryDemo")
    public String queryDemo(@SpringQueryMap DemoDTO demoDTO){
        String str = demoProvider.queryDemoDTO(demoDTO);
        return str;
    }
}
